package com.mjfeed.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.mjfeed.dto.api.ReceiverJSON;
import com.mjfeed.dto.api.ReceiverListJSON;
import com.mjfeed.entity.Receiver;
import com.mjfeed.service.ReceiverService;

@Service("receiverService")
public class ReceiverServiceImpl extends BaseServiceImpl implements ReceiverService {

	@Override
	public ReceiverListJSON searchToJSON(List<Receiver> receivers) {
		if (receivers != null) {
			ReceiverListJSON receiverListJSON = new ReceiverListJSON();
			List<ReceiverJSON> recordList = new ArrayList<ReceiverJSON>();
			for (Receiver receiver : receivers) {
				ReceiverJSON receiverJSON = new ReceiverJSON();
				receiverJSON.setReceiverId(receiver.getId());
				receiverJSON.setAddress(receiver.getAddress());
				receiverJSON.setAreaId(receiver.getArea().getId());
				receiverJSON.setAreaName(receiver.getAreaName());
				receiverJSON.setConsignee(receiver.getConsignee());
				receiverJSON.setIsDefault(receiver.getIsDefault());
				receiverJSON.setPhone(receiver.getPhone());
				receiverJSON.setZipCode(receiver.getZipCode());
				recordList.add(receiverJSON);
			}
			receiverListJSON.setRecordList(recordList);
			return receiverListJSON;
		}
		return null;
	}

	@Override
	public ReceiverJSON beanToJSON(Receiver receiver) {
		if (receiver != null) {
			ReceiverJSON receiverJSON = new ReceiverJSON();
			receiverJSON.setReceiverId(receiver.getId());
			receiverJSON.setAddress(receiver.getAddress());
			receiverJSON.setAreaId(receiver.getArea().getId());
			receiverJSON.setAreaName(receiver.getAreaName());
			receiverJSON.setConsignee(receiver.getConsignee());
			receiverJSON.setIsDefault(receiver.getIsDefault());
			receiverJSON.setPhone(receiver.getPhone());
			receiverJSON.setZipCode(receiver.getZipCode());
			return receiverJSON;
		}
		return null;
	}

}
